Skip to content

Conversation

@ellemouton
Copy link
Member

@ellemouton ellemouton commented Mar 4, 2025

This PR just defines the SQL Schemas and queries. The following diagram shows the new tables and the relations between them along with the optional link between the sessions and accounts table.

Basically today all of this data is stored in a single serialised session but in SQL land, we want the data to be completely normalised.

This PR is just 1 commit & an ACK here is more about understanding & agreeing with the defined schema.
If you'd like, it may make sense to review while glancing at the follow up which actually adds the CRUD to interact
with the new schema. But if we end up making minor changes to queries in the follow up after this is merged, it is no big deal as nothing activates this code in this PR.

lit-sql (6)

@ellemouton ellemouton added no-changelog This PR is does not require a release notes entry sql-ize labels Mar 4, 2025
@ellemouton ellemouton self-assigned this Mar 4, 2025
@ellemouton ellemouton marked this pull request as draft March 4, 2025 15:52
@ellemouton ellemouton force-pushed the sql21Sessions13 branch 2 times, most recently from fc95724 to f06e75c Compare March 6, 2025 11:06
@ellemouton ellemouton changed the title [sql-21] sessions: SQL Schemas & CRUD [sql-21] sessions: SQL schemas & queries Mar 6, 2025
@ellemouton ellemouton marked this pull request as ready for review March 6, 2025 11:11
Copy link
Contributor

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉 nice work!

Copy link
Contributor

@ViktorT-11 ViktorT-11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀! Leaving a few suggestions that I think will be useful.

Comment on lines +65 to +66
-- ID to use for the group ID.
group_id BIGINT REFERENCES sessions(id) ON DELETE CASCADE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create an index for this as there's a queries using this as the identifier?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, interesting - I thought foreign keys where automatically indexed. Turns out that is incorrect - so yes, will add 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so yeah great catch - i totally had the wrong assumption - It also means i need to add indices for the tables below on any foreign key


-- The session_macaroon_permissions table contains the macaroon permissions
-- that are associated with a session.
CREATE TABLE IF NOT EXISTS session_macaroon_permissions (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think it makes sense to include an id field for this table, session_feature_configs & session_privacy_flags as it'll likely be useful in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so i think it makes sense to add the id for mac perms and caveats since those are lists and not necessarily unique but think for feature configs and priv flags, it does not make sense to add id since those will always have a unique foreign-key:one-other-field pair.

sound good?

@ellemouton ellemouton force-pushed the sql21Sessions13 branch 2 times, most recently from f855adb to 873e0f5 Compare March 10, 2025 19:01
Copy link
Member Author

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ViktorTigerstrom - could you take one last look at the last push (second last compare) 🙏

Copy link
Contributor

@ViktorT-11 ViktorT-11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after addressing @bitromortac last comment :) 🚀!

This commit adds all the schema definitions we require for the sessions
store.
@ellemouton ellemouton merged commit 64ab73a into lightninglabs:master Mar 11, 2025
17 of 21 checks passed
@ellemouton ellemouton deleted the sql21Sessions13 branch March 11, 2025 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This PR is does not require a release notes entry sql-ize

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants